<template>
  <div>
    <el-form :inline="true" :model="query" class="num2">
      <el-form-item label="灯杆编号:" class="num1">
        <el-input
          v-model="query.lpName"
          placeholder="灯杆编号"
          class="num3"
        ></el-input>
      </el-form-item>
      <el-form-item label="巡检人:">
        <el-input v-model="query.userName" placeholder="巡检人"></el-input>
      </el-form-item>
      <el-form-item label="巡检时间:">
        <el-date-picker
          v-model="query.dateRange"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit2">重置</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="dialog.addshow = true"
          >新增</el-button
        >
      </el-form-item>
    </el-form>

    <el-dialog title="新增用户" :visible.sync="dialog.addshow" width="30%">
      <el-form :model="addForm" :rules="rules" ref="addForm">
        <el-form-item label="设备编号：" >
          <el-select v-model="addForm.facId" placeholder="设备编号" class="num6">
            <el-option label="区域一" value="shanghai"></el-option>
            <el-option label="区域二" value="beijing"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="灯杆编号：" >
          <el-select v-model="addForm.lpid" placeholder="灯杆编号" class="num6">
            <el-option 
            v-for="item in areas"
            :key="item.lpName"
            :label="item.lpName"
            :value="item.lpid"></el-option>
            
          </el-select>
        </el-form-item>
        
        <el-form-item label="巡检时间：" >
          <el-input v-model="addForm.inspectionData" placeholder="按照1990-01-01输入"  style="width:46%;margin-right: 145px"></el-input>
        </el-form-item>
        
        <el-form-item label="巡检人：" >
          <el-select v-model="addForm.userName" placeholder="巡检人" class="num4">
            <el-option label="区域一" value="shanghai"></el-option>
            <el-option label="区域二" value="beijing"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="巡检内容：" >
          <el-input v-model="addForm.inspectionDesc" placeholder="请输入巡检内容"  style="width:50%;margin-right: 127px"></el-input>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="dialog.addshow = false">取 消</el-button>
        <el-button type="primary" @click="addPolling = true">提交</el-button>
      </div>
    </el-dialog>

    <el-button type="primary" @click="onSubmit4" class="num5"
      >导出数据</el-button
    >
    <el-button type="primary" @click="onSubmit5">导入数据</el-button>
    <el-table
      ref="multipleTable"
      :data="PollingList"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column prop="facId" label="设备编号" width="230">
      </el-table-column>
      <el-table-column prop="lpName" label="灯杆编号" width="230">
      </el-table-column>
      <el-table-column prop="inspectionDesc" label="巡检内容" width="250">
      </el-table-column>
      <el-table-column prop="inspectionData" label="巡检时间" width="250">
      </el-table-column>
      <el-table-column prop="userName" label="巡检人" show-overflow-tooltip>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.row.id)"
            >编辑</el-button
          >
          <el-popconfirm
            title="这是一段内容确定删除吗？"
            @confirm="handleDelete(scope.row.id)"
          >
            <el-button slot="reference" size="mini" type="danger"
              >删除</el-button
            >
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      PollingList: [],
      query: {
        lpName: "",
        userName: "",
        dateRange: [],
      },
      dialog: {
        addshow: false,
      },
      addForm: {},
    };
  },
  methods: {
    loadPolling() {
      this.$axios.get("/inspction").then((res) => {
        this.PollingList = res.data.data.list;
      });
    },
    onSubmit() {
      this.loadquery();
    },
    onSubmit2() {
      this.query = {};
      this.loadquery();
    },
    loadquery() {
      this.$axios.post("/inspction/query", this.query).then((res) => {
        this.PollingList = res.data.data.query;
      });
    },
    addPolling() {
      this.$axios.post("/inspction", this.addForm).then((res) => {
        if (res.data.code == 200) {
          this.dialog.addshow = false;
          this.loadPolling();
          this.$$refs.addshow.resetFields();
        }
      });
    },
    selightPole () {
      this.$axios.get("/inspction", this.addForm).then((res) => {
        if (res.data.code == 200) {
          this.dialog.addshow = false;
          this.loadPolling();
          this.$$refs.addshow.resetFields();
        }
      });
    },
  },
  mounted() {
    this.loadPolling();
  },
};
</script>
<style scoped>
.num2 {
  line-height: 20px;
}
.num5 {
  margin-left: 74%;
}
.num4 { 
  margin-right: 133px;
}
.num6 { 
  margin-right: 145px;
}
.num7 {
  height: 20%;
}
</style>